home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / PRSWAP.ASM < prev    next >
Assembly Source File  |  1986-02-05  |  5KB  |  122 lines

  1. ; Program to swap IBM PC text graphics
  2. ; characters for something more printable.
  3. ;
  4. VECTORS     segment at 0h        ; Interrupt Vector Area
  5.     org    17h*4            ; IBM PC Printer is Int 17H
  6. PR_INT_VECTOR    label    dword        ; Double Word Offset:Segment pointer
  7. VECTORS     ends            ; to Int 17H
  8. ;
  9. CODE_SEG    segment para public 'code'
  10.     assume    ds:CODE_SEG, cs:CODE_SEG, es:CODE_SEG, ss:NOTHING
  11.     org    100h            ; COM program format
  12. ;
  13. BEGIN:    jmp    SWAP_VECTORS        ; Initialize vectors and
  14.                     ; attach PRSWAP to DOS
  15. ROM_PR_INT    dd    0        ; Double word to save address of
  16.                     ; ROM-BIOS printer interrupt
  17. ;
  18. ; Swap table to translate (XLAT) characters to be printed
  19. ;
  20. SWAP_TABLE    db    '&'             ; Char 176      Graphic Fill
  21.         db    '%'             ; Char 177      Graphic Fill
  22.         db    '@'             ; Char 178      Graphic Fill
  23.         db    4 dup ('|')     ; Char 179-182  Vertical
  24.         db    2 dup ('*')     ; Char 183-184  Corner
  25.         db    2 dup ('|')     ; Char 185-186  Vertical
  26.         db    6 dup ('*')     ; Char 187-192  Corner
  27.         db    2 dup ('-')     ; Char 193-194  Horizontal
  28.         db    '|'             ; Char 195      Vertical
  29.         db    '-'             ; Char 196      Horizontal
  30.         db    '+'             ; Char 197      Intersection
  31.         db    2 dup ('|')     ; Char 198-199  Vertical
  32.         db    2 dup ('*')     ; Char 200-201  Corner
  33.         db    2 dup ('-')     ; Char 202-203  Horizontal
  34.         db    '|'             ; Char 204      Vertical
  35.         db    '-'             ; Char 205      Horizontal
  36.         db    '+'             ; Char 206      Intersection
  37.         db    4 dup ('-')     ; Char 207-210  Horizontal
  38.         db    4 dup ('*')     ; Char 211-214  Corner
  39.         db    2 dup ('+')     ; Char 215-216  Intersection
  40.         db    2 dup ('*')     ; Char 217-218  Corner
  41.         db    '#'             ; Char 219      Graphic Fill
  42.         db    '.'             ; Char 220      Graphic Fill
  43.         db    '{'             ; Char 221      Graphic Fill
  44.         db    '}'             ; Char 222      Graphic Fill
  45.         db    '^'             ; Char 223      Graphic Fill
  46. ;
  47. ; Miscellaneous equates
  48. ;
  49. PRINT_CHAR    equ    0        ; Int 17H print char function number
  50. LOWEST_CHAR    equ    176        ; Lowest graphic char in table
  51. HIGHEST_CHAR    equ    223        ; Highest graphic char in table
  52. LOZENGE     equ    254        ; Lozenge character position
  53. ;
  54. PRSWAP    proc    near            ; Work begins here
  55.     push    cx            ; Save CX on stack
  56.     xor    cx,cx            ; Clear CX so flag works
  57.     push    ds            ; Save caller's DS on stack
  58.     push    cs            ; Push CS, then pop it as DS
  59.     pop    ds            ; to establish addressability
  60.                     ; of PRSWAP's data
  61.     cmp    ah,PRINT_CHAR        ; Is call for printing a char?
  62.     ja    CALL_INT_17H        ; No, go to normal interrupt 17H
  63.     cmp    al,LOWEST_CHAR        ; Is char to print below table range?
  64.     jb    CALL_INT_17H        ; Yes, go to normal interrupt 17H
  65.     cmp    al,HIGHEST_CHAR     ; Is char to print above table range
  66.     ja    CHECK_LOZENGE        ; Yes, check for lozenge char
  67.     mov    cl,al            ; Save char in AL register in CL
  68.     push    bx            ; Save BX on stack
  69.     mov    bx,offset SWAP_TABLE    ; Point to translate table with BX
  70.     sub    al,LOWEST_CHAR        ; Adjust AL for bias into table
  71.     xlat                ; Translate to PRSWAP's character
  72.     pop    bx            ; Restore BX
  73.     jmp    CALL_INT_17H        ; Go call interrupt 17H
  74. CHECK_LOZENGE:                ; Check for char 254
  75.     cmp    al,LOZENGE        ; Is char to print the lozenge?
  76.     jne    CALL_INT_17H        ; No, go to normal interrupt 17H
  77.     mov    cl,al            ; Save char in AL register in CL
  78.     mov    al,'='                  ; Make it a '='
  79. CALL_INT_17H:                ; Go call Int 17H as subroutine
  80.     pushf                ; Push flags for fake interrupt 17H
  81.     call    ROM_PR_INT        ; Call interrupt 17H as subroutine
  82.     cmp    cl,0            ; Check to see if PRSWAP did anything
  83.     je    RETURN            ; If not, just return
  84.     mov    al,cl            ; Restore original char to AL
  85. RETURN:                 ; Return to caller
  86.     pop    ds            ; Restore caller's DS register
  87.     pop    cx            ; Restore caller's CX register
  88.     iret                ; Interrupt return to caller
  89.     PRSWAP    endp            ; That's all for resident routine
  90. ;
  91. INITIAL_DATA:                ; Messages for initialization code
  92. ;
  93. COPYRIGHT    db    'PRSWAP (C) 1985, Dickinson Associates Inc.',13,10,'$'
  94. FINISH_MSG    db    13,10,'Resident Portion of PRSWAP Loaded',13,10,10,'$'
  95. ;
  96. SWAP_VECTORS:                ; Initialization Code
  97.     assume    ds:CODE_SEG        ; Address into this segment
  98.     mov    dx,offset COPYRIGHT    ; Set up to print copyright notice
  99.     mov    ah,9h            ; Request DOS to display string
  100.     int    21h            ; Call DOS
  101.     push    ds            ; Save this segment
  102.     assume    ds:VECTORS        ; Address into VECTORS segment
  103.     mov    ax,VECTORS        ; Establish DS as VECTORS
  104.     mov    ds,ax
  105.     cli                    ; Disable interrupts
  106.     mov    ax,word ptr PR_INT_VECTOR    ; Store addresses
  107.     mov    word ptr es:ROM_PR_INT,ax    ; of BIOS Int 17H program
  108.     mov    ax,word ptr PR_INT_VECTOR[2]
  109.     mov    word ptr es:ROM_PR_INT[2],ax
  110.     mov    word ptr PR_INT_VECTOR, offset PRSWAP    ; Substitute PRSWAP
  111.     mov    word ptr PR_INT_VECTOR[2],cs        ; and this segment
  112.     sti                ; Enable interrupts
  113.     pop    ds            ; Re-establish this segment
  114.     assume    ds:CODE_SEG        ; as DS
  115.     mov    dx,offset FINISH_MSG    ; Set up to display finish message
  116.     mov    ah,9h            ; Request DOS to display string
  117.     int    21h            ; Call DOS
  118.     mov    dx,offset INITIAL_DATA  ; End of PRSWAP program
  119.     int    27h            ; Terminate, stay resident
  120. CODE_SEG    ends            ; End of Segment
  121.     end    BEGIN            ; End of Everything
  122.